package com.ng.finance.api.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.ng.finance.api.service.UserPayService;
import com.ng.finance.api.vo.UserPayVo;
import com.ng.finance.common.pojo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 83673
 * @since 2018-09-14
 */
@RestController
@RequestMapping("/api/userPay")
public class UserPayController {
    @Resource
    UserPayService userPayService;

    /**
     * 记录我的消费
     */
    @PostMapping(value = "recordPay")
    public Result recordPay(@Valid UserPayVo userPay) {
        return userPayService.recordPay(userPay);

    }

    /**
     * 编辑我的消费
     */
    @PostMapping(value = "updatePay")
    public Result updatePay(@Valid UserPayVo userPay) {


        return userPayService.updatePay(userPay);
    }


    /**
     * 已阅
     */
    @GetMapping(value = "alreadyRead")
    public Result alreadyRead(@NotNull @RequestParam Integer lookState, @NotNull @RequestParam long id) {
        return userPayService.alreadyRead(lookState, id);
    }

    /**
     * 查询个人记录列表
     */
    @GetMapping(value = "selectPersonPayList")
    public Result selectPersonPayList(@NotNull @RequestParam String payTime, Page page) {
        return userPayService.selectPersonPayList(payTime, page);

    }

    /**
     * 查询个人记总消费
     */
    @GetMapping(value = "selectPersonPay")
    public Result selectPersonPay() {
        return userPayService.selectPersonPay();

    }

    /**
     * 删除我的消费记录
     */

    @GetMapping(value = "deleteMyPay")
    public Result deleteMyPay(@NotNull @RequestParam String id) {
        return userPayService.deleteMyPay(id);

    }


    /**
     * 查阅----未阅   待报销
     */
    @GetMapping(value = "selectNoReadList")
    public Result selectNoReadList(String userId, Integer payType, Integer lookState, String payTime, Page page) {
        return userPayService.selectNoReadList(userId, payType, lookState, payTime, page);
    }


    /**
     * 批量已阅
     */
    @PostMapping(value = "moreReadByUserId")
    public Result moreReadByUserId(String ids) {
        return userPayService.moreReadByUserId(Arrays.asList(ids.split(";")));

    }


    /**
     * 批量生成报销单
     */
    @PostMapping(value = "moreUnreimbursed")
    public Result moreUnreimbursed(String ids, String moneys, String time, Long userId) {
        return userPayService.moreUnreimbursed(Arrays.asList(ids.split(";")), Arrays.asList(moneys.split(";")), time, userId, ids);

    }
}

